package com.awb.rabbitmqdemo.routing;

import com.awb.rabbitmqdemo.entity.MessageBody;
import com.awb.rabbitmqdemo.fanout.FanoutConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class RoutingProcuer {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendInfo(){
        MessageBody<String> messageBody = new MessageBody<>();
        messageBody.setBusType("direct模式");
        messageBody.setBusCode("direct");
        messageBody.setData("消息体info");

        System.out.println("direct发送消息"+messageBody);

        rabbitTemplate.convertAndSend(RoutingConfig.ROUTING_EXCHANGE, "info", messageBody);

    }

    public void sendError(){
        MessageBody<String> messageBody = new MessageBody<>();
        messageBody.setBusType("direct模式");
        messageBody.setBusCode("direct");
        messageBody.setData("消息体error");

        System.out.println("direct发送消息"+messageBody);

        rabbitTemplate.convertAndSend(RoutingConfig.ROUTING_EXCHANGE, "error", messageBody);

    }
}
